package com.xueyl.springboot.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private JdbcTemplate jdbcTemplatel;

	@Override
	public void create(String name, Integer age, String password) {
		jdbcTemplatel.update("insert into USER(NAME,AGE,PASSWORD) values(?,?,?)",name,age,password);
	}

	@Override
	public void deleteByName(String name) {
		jdbcTemplatel.update("delete  from USER where name = ?", name);

	}

	@Override
	public Integer getAllUsers() {
		return jdbcTemplatel.queryForObject("select COUNT(0) from USER", Integer.class);
	}

	@Override
	public void deleteAllUsers() {
		jdbcTemplatel.update("delete from USER");
	}

}
